//
//  HomeTableViewCell.m
//  PersonalOC
//
//  Created by 韩琴 on 2018/8/17.
//  Copyright © 2018年 韩琴. All rights reserved.
//

#import "HomeTableViewCell.h"
@interface HomeTableViewCell ()

@property (strong,nonatomic) UILabel *titleLable;
@property (strong,nonatomic) UILabel *moneylable;
@property (strong,nonatomic) UILabel *addressAndTimeAndEducationlable;
@property (strong,nonatomic) UILabel *statusLable;
@property (strong,nonatomic) UIView *tagView;
@property (strong,nonatomic) UILabel *companyLabel;

@end
@implementation HomeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
   self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self loadUI];
    }
    return self;
}
-(void)loadUI {
    //初始化
    self.titleLable = [[UILabel alloc] init];
     self.moneylable = [[UILabel alloc] init];
     self.addressAndTimeAndEducationlable = [[UILabel alloc] init];
     self.statusLable = [[UILabel alloc] init];
     self.companyLabel = [[UILabel alloc] init];
    self.tagView = [[UIView alloc] init];
    //添加
    [self.contentView addSubview:self.titleLable];
    [self.contentView addSubview:self.moneylable];
    [self.contentView addSubview:self.addressAndTimeAndEducationlable];
    [self.contentView addSubview:self.statusLable];
    [self.contentView addSubview:self.companyLabel];
    [self.contentView addSubview:self.tagView];
    
//    self.titleLable.backgroundColor = UIColor.redColor;
//    self.moneylable.backgroundColor = UIColor.grayColor;
//    self.addressAndTimeAndEducationlable.backgroundColor = UIColor.blueColor;
//    self.statusLable.backgroundColor = UIColor.yellowColor;
//    self.companyLabel.backgroundColor = UIColor.greenColor;
//    self.tagView.backgroundColor = UIColor.purpleColor;
    //布局
    [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(8);
        make.height.mas_equalTo(21);
        make.bottom.equalTo(self.addressAndTimeAndEducationlable.mas_top);
    }];
    [self.moneylable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(8);
//        make.width.mas_equalTo(80);
    }];
    [self.addressAndTimeAndEducationlable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLable.mas_left);
        make.top.equalTo(self.titleLable.mas_bottom);
        make.right.equalTo(self.moneylable.mas_left).mas_offset(-8);
        make.height.mas_equalTo(17);
        make.bottom.equalTo(self.tagView.mas_top);
    }];
    [self.statusLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.moneylable.mas_right);
        make.top.equalTo(self.addressAndTimeAndEducationlable.mas_top);
        
    }];
    [self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLable.mas_left);
        make.top.equalTo(self.addressAndTimeAndEducationlable.mas_bottom);
        make.height.mas_offset(25);
         make.right.equalTo(self.moneylable.mas_right);
        make.bottom.equalTo(self.companyLabel.mas_top);
    }];
    [self.companyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.titleLable.mas_left);

//        make.right.equalTo(self.moneylable.mas_right);
        make.height.mas_equalTo(17);
        make.top.equalTo(self.tagView.mas_bottom);
    }];
    //属性
    self.titleLable.font = LY_S_BOLD_FONT(14);
    self.moneylable.font = LY_S_BOLD_FONT(14);
    self.addressAndTimeAndEducationlable.font = LY_S_BOLD_FONT(10);
    self.statusLable.font = LY_S_BOLD_FONT(10);
    self.companyLabel.font = LY_S_BOLD_FONT(10);
    self.moneylable.textColor = [UIColor redColor];
    self.addressAndTimeAndEducationlable.textColor = [UIColor lightGrayColor];
    self.statusLable.textColor = [UIColor lightGrayColor];
    self.companyLabel.textColor = [UIColor darkGrayColor];
    self.moneylable.textAlignment = NSTextAlignmentRight;
}
- (void)setCellModle:(HomeModle *)cellModle {
    self.titleLable.text = cellModle.title;
    self.moneylable.text = cellModle.money;
    self.companyLabel.text = cellModle.company;
    self.addressAndTimeAndEducationlable.text = [NSString stringWithFormat:@"%@ I %@ I %@",cellModle.address,cellModle.time,cellModle.edu];
    self.statusLable.text = cellModle.status;
    [self.tagView ly_removeAllSubviews];
    CGFloat currentX = 0;
    for (int i = 0; i < cellModle.tagsArrary.count;i++) {
        UILabel *tagLbale = [[UILabel alloc] init];
        tagLbale.textColor = UIColor.lightGrayColor;
        tagLbale.backgroundColor = UIColor.groupTableViewBackgroundColor;
        tagLbale.text = cellModle.tagsArrary[i];
        tagLbale.font = LY_S_FONT(10);
        [self.tagView addSubview:tagLbale];
        [tagLbale sizeToFit];
        tagLbale.frame = CGRectMake(currentX, 5, tagLbale.size.width, 15);
        currentX = currentX + tagLbale.size.width + 8;
    }
}
@end
